package com.demo.arch.datapulsedemo.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 查询条件
 * 
 * @author DataPulse Team
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QueryCondition {

  /**
   * 报表类型
   */
  private String reportType;

  /**
   * 开始时间
   */
  private LocalDateTime startTime;

  /**
   * 结束时间
   */
  private LocalDateTime endTime;

  /**
   * 客户名称
   */
  private String customerName;

  /**
   * 订单状态
   */
  private String status;

  /**
   * 最小金额
   */
  private java.math.BigDecimal minAmount;

  /**
   * 最大金额
   */
  private java.math.BigDecimal maxAmount;

  /**
   * 排序字段
   */
  private String sortBy;

  /**
   * 排序方向
   */
  private String sortDirection;

  /**
   * 页码
   */
  private Integer pageNumber;

  /**
   * 每页大小
   */
  private Integer pageSize;

  /**
   * 标签
   */
  private List<String> tags;

  /**
   * 是否包含已取消订单
   */
  private Boolean includeCancelled;

  /**
   * 根据报表类型创建默认查询条件
   */
  public static QueryCondition fromReportType(String reportType) {
    QueryCondition condition = new QueryCondition();
    condition.setReportType(reportType);

    LocalDateTime now = LocalDateTime.now();

    switch (reportType) {
      case "日报":
        condition.setStartTime(now.toLocalDate().atStartOfDay());
        condition.setEndTime(now);
        break;
      case "周报":
        condition.setStartTime(now.minusDays(7));
        condition.setEndTime(now);
        break;
      case "月报":
        condition.setStartTime(now.minusDays(30));
        condition.setEndTime(now);
        break;
      case "年报":
        condition.setStartTime(now.minusDays(365));
        condition.setEndTime(now);
        break;
      default:
        condition.setStartTime(now.minusDays(1));
        condition.setEndTime(now);
    }

    condition.setSortBy("orderTime");
    condition.setSortDirection("DESC");
    condition.setIncludeCancelled(true);

    return condition;
  }
}
